home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / shell-tools / flp_by_anp / wbrst.doc < prev    next >
Text File  |  1996-02-24  |  14KB  |  293 lines

  1.  
  2. *****************************************************************************
  3. * Project Details                                                           *
  4. * ---------------                                                           *
  5. * Project Name:    WBRst                                                    *
  6. * Project Version: 1                                                        *
  7. * Copyright:       Anthony N Peck                                           *
  8. * Date:            Tuesday 23rd May 1995                                    *
  9. *                                                                           *
  10. * Contact:                                                                  *
  11. * 68 Woralul ST                                                             *
  12. * Waramanga ACT 2611                                                        *
  13. * AUSTRALIA                                                                 *
  14. *                                                                           *
  15. * E-Mail: Anthony.Peck@Radford.act.edu.au                                   *
  16. *                                                                           *
  17. *****************************************************************************
  18. *                                                                           *
  19. * File Summary                                                              *
  20. * ------------                                                              *
  21. *                                                                           *
  22. * Usage: WBRst                                                              *
  23. *                                                                           *
  24. * Like it's fellow Rst, it is a small rebooting program.  Unlike Rst, this  *
  25. * one can be run and executed via the Workbench.  Being for Workbench users *
  26. * it also has a safety net if pressed accidentally.  There's a small strip  *
  27. * to move the window if you wish, alternatively you could alter the window  *
  28. * definitions below and re-compile!                                         *
  29. *                                                                           *
  30. * THIS PROGRAM AUTO-DETACHES FROM THE CLI - ALTHOUGH I DIDN'T INCLUDE THE   *
  31. * SOURCE FOR THAT HERE BECAUSE IT ISN'T MINE!                               *
  32. *                                                                           *
  33. *****************************************************************************
  34.  
  35. *********************************************************************
  36. *                                                                   *
  37. * Some Useful Definitions                                           *
  38. * -----------------------                                           *
  39. *                                                                   *
  40. * You'll find all of these in the various includes that come with   *
  41. * a compiler like DevPac.  Some are defined in structures such as   *
  42. * "GADGET", while others are library offsets.  If you are stuck for *
  43. * such definitions, check out HexTract by Chas Wyndham (Fish 817).  *
  44. *                                                                   *
  45. *********************************************************************
  46.  
  47. ; Simple equivalents
  48.  
  49. ExecBase                = $04      ; ExecBase (!)
  50. Wd_userport             = $56      ; Window UserPort (Window structure)
  51. Pr_cli                  = $AC      ; CLI offset in process structure
  52. Pr_msgport              = $5C      ; Message port for process structure
  53. Im_class                = $14      ; Class for IDCMP message
  54. Iaddress                = $1C      ; Address of IDCMP message
  55.  
  56. ; Library Vector Offsets
  57.  
  58. _LVOOpenlibrary         = -$0228   ; Exec function
  59. _LVOOpenwindow          = -$CC     ; Intuition function
  60. _LVOWaitport            = -$0180   ; Exec function
  61. _LVOFindtask            = -$0126   ; Exec function
  62. _LVOForbid              = -$84     ; Exec function
  63. _LVOSetwindowtitles     = -$0114   ; Intuition function
  64. _LVOGetmsg              = -$0174   ; Exec function
  65. _LVOReplymsg            = -$017A   ; Exec function
  66. _LVOAutoRequest         = -$015C   ; Intuition function
  67.  
  68. *********************************************************************
  69. *                                                                   *
  70. * Some Useful Macros                                                *
  71. * ------------------                                                *
  72. *                                                                   *
  73. * Macros waste memory and increase the size of the code, but they   *
  74. * make life a bit easier and the code a bit more readable.  All of  *
  75. * these are used to access the appropriate library functions.  The  *
  76. * library bases are loaded, the LVO prefix is added, and then the   *
  77. * function is called.  Simple!                                      *
  78. *                                                                   *
  79. *********************************************************************
  80.  
  81. EXEC            Macro
  82.         MOVE.L  ExecBase,A6        ; Move Exec into a6
  83.         JSR     _LVO\1(A6)         ; Add Library offset and call function
  84.                 Endm
  85.  
  86. CALLINT         Macro
  87.         MOVE.L  _intuitionbase,A6  ; Move Intuition into a6
  88.         JSR     _LVO\1(A6)         ; Add Library offset and call function
  89.                 Endm
  90.  
  91. *********************************************************************
  92. *                                                                   *
  93. * Wb Startup Code                                                   *
  94. * ---------------                                                   *
  95. *                                                                   *
  96. * I modified this slightly from that which is provided with the     *
  97. * includes that come with DevPac.  You can get similiar code        *
  98. * in the Public Domain, see STARTUPS on Fish 101.  All they do is   *
  99. * allow you to start your program from WB.                          *
  100. *                                                                   *
  101. *********************************************************************
  102.  
  103.         MOVEM.L  D0/A0,-(SP)        ;    save initial values
  104.         CLR.L    Returnmsg          ;    clear message
  105.         SUB.L    A1,A1              ;    subtract address
  106.         EXEC     Findtask           ;    find us
  107.         MOVE.L   D0,A4              ;    move process to a4
  108.         TST.L    Pr_cli(A4)         ;    test if CLI
  109.         BEQ      Fromworkbench      ;    otherwise go to workbench
  110.         MOVEM.L  (SP)+,D0/A0        ;    restore registers
  111.         BRA      End_startup        ;    and run the program
  112.  
  113. Fromworkbench:
  114.  
  115.         LEA      Pr_msgport(A4),A0  ;    load the message port
  116.         EXEC     Waitport           ;    wait for a message
  117.         LEA      Pr_msgport(A4),A0  ;    load the message port
  118.         EXEC     Getmsg             ;    then get it
  119.         MOVE.L   D0,Returnmsg       ;    save it for later reply
  120.         MOVEM.L  (SP)+,D0/A0        ;    restore registers
  121.  
  122. End_startup:
  123.  
  124.         BSR      Start              ;    call the program
  125.         MOVE.L   D0,-(SP)           ;    save it
  126.         TST.L    Returnmsg          ;    test if message
  127.         BEQ      Exittodos          ;    if I was a CLI
  128.         EXEC     Forbid             ;    forbid WB to close
  129.         MOVE.L   Returnmsg(Pc),A1   ;    load message
  130.         EXEC     Replymsg           ;    message received!
  131.  
  132. Exittodos:
  133.  
  134.         MOVE.L   (SP)+,D0           ;    exit code
  135.         RTS
  136.  
  137. *********************************************************************
  138. *                                                                   *
  139. * Program Starts Here                                               *
  140. * -------------------                                               *
  141. *                                                                   *
  142. * The above code points to this Start identifier, which is where    *
  143. * the actual program starts!                                        *
  144. *                                                                   *
  145. *********************************************************************
  146.  
  147. Start:
  148.  
  149. ; The opening of the intuition library, including an error branch if things
  150. ; don't go according to plan!
  151.  
  152.         LEA      Intname,A1         ; Load intuition library into a1
  153.         EXEC     Openlibrary        ; Macro opens library
  154.         BEQ      Exittodos          ; If it doesn't open, we quit
  155.         MOVE.L   D0,_intuitionbase  ; Save the return address
  156.  
  157. ; This little bit opens the dinky little window.
  158.  
  159.         LEA     Win_defs,A0         ; Load window definitions to a0
  160.         CALLINT Openwindow          ; Macro opens window
  161.         MOVE.L  D0,Winhd            ; Save return address (window handle)
  162.  
  163. ; Here the screen title is changed.
  164.  
  165.         MOVE.L  Winhd,A0            ; Move window handle into a0
  166.         LEA     WinName,A1          ; Move current window title into a1
  167.         LEA     Screentitle,A2      ; Load the screen title into a2
  168.         CALLINT Setwindowtitles     ; Macro changes screen title
  169.  
  170. Mainloop:
  171.  
  172.         MOVE.L   Winhd,A0           ; Move window handle into a0
  173.         MOVE.L   Wd_userport(A0),A0 ; UserPort offset at byte 86
  174.         EXEC     Waitport           ; Macro waits for message from window
  175.         MOVE.L   Winhd,A0           ; Move window handle into a0
  176.         MOVE.L   Wd_userport(A0),A0 ; UserPort offset
  177.         EXEC     Getmsg             ; Macro gets window message
  178.         MOVE.L   D0,A1              ; Message transferred to a1
  179.         EXEC     Replymsg           ; Message received!
  180.  
  181.         MOVE.L   Winhd,A0           ; Load the window handle to A0...
  182.         LEA      Atext,A1           ; ...and the main body text to A1...
  183.         LEA      Ltext,A2           ; ...and the left text to A2...
  184.         LEA      Rtext,A3           ; ...and the right text to A3
  185.         MOVE.L   #$00,D0            ; left button responds to mouse click
  186.         MOVE.L   #$00,D1            ; right button responds to mouse click
  187.         MOVE.L   #$C4,D2            ; requester length
  188.         MOVE.L   #$35,D3            ; requester height
  189.         CALLINT  AutoRequest        ; call the requester
  190.         TST.B    D0                 ; Test if clicked the right button
  191.         BNE      Mainloop           ; No...so back for another message
  192.  
  193. Bang:
  194.  
  195. ; Clear the vectors and reboot
  196.  
  197.         MOVE.L  $04,A6              ; ExecBase to A6
  198.         CLR.L   $32(A6)             ; Clear Warm Capture
  199.         CLR.L   $2E(A6)             ; Clear Cool Capture
  200.         CLR.L   $2A(A6)             ; Clear Cold Capture
  201.         CLR.L   $226(A6)            ; Clear KickTagPtr
  202.  
  203.         LEA     Boot,A5             ; Load boot routine to A5
  204.         JSR     -$1E(A6)            ; Supervisor mode reboot
  205.  
  206. Boot:   LEA     $F000000,A0         ; Load end of ROM to A0
  207.         RESET                       ; Stack pointer for supervisor mode
  208.         JMP     (A0)                ; Jump and gone...
  209.  
  210. *********************************************************************
  211. *                                                                   *
  212. * Structures and Memory Allocation                                  *
  213. * --------------------------------                                  *
  214. *                                                                   *
  215. * Here are the definitions held for the structures used in the      *
  216. * program, as well as memory blocks set aside for definitions such  *
  217. * as the messages.                                                  *
  218. *                                                                   *
  219. *********************************************************************
  220.  
  221. Win_defs:
  222.  
  223. ; Window structure (some help here from FASTWINDOWS by R Plant)
  224.  
  225.         DC.W $226                   ; Wdw X    | Alter position of window
  226.         DC.W $00                    ; Wdw Y    | using these two values
  227.         DC.W $19                    ; Wdw W
  228.         DC.W $B                     ; Wdw H
  229.         DC.B $01                    ; Col 0
  230.         DC.B $00                    ; Col 1
  231.         DC.L $00000200              ; IDCMP
  232.         DC.L $0000000A              ; TYPE
  233.         DC.L $00                    ; No Gadgets
  234.         DC.L $00                    ; Standard Checkmark
  235.         DC.L WinName                ; Window name 
  236.         DC.L $00                    ; screen pointer
  237.         DC.L $00                    ; no custom bitmap
  238.         DC.W $00,$00,$00,$00        ; intuition sets these given that...
  239.         DC.W $01                    ; this is a WORKBENCH screen 
  240.  
  241. Atext:
  242.  
  243. ; Intuitext structure
  244.  
  245.         DC.B    $02,$01,$01         ; FrontPen,BackPen,DrawMode
  246.  
  247.         Even                        ; Fill to make even address for word
  248.  
  249.         DC.W    $0D,$08             ; Left edge, top edge
  250.         DC.L    $00                 ; No special font
  251.         DC.L    Atx                 ; The actual text
  252.         DC.L    $00                 ; No next text 
  253.  
  254. Ltext:
  255.  
  256. ; Intuitext structure
  257.  
  258.         DC.B    $02,$01,$01         ; FrontPen,BackPen,DrawMode
  259.  
  260.         Even                        ; Fill to make even address for word
  261.  
  262.         DC.W    $06,$03             ; Left edge, top edge
  263.         DC.L    $00                 ; No special font
  264.         DC.L    Ltx                 ; The actual text
  265.         DC.L    $00                 ; No next text 
  266.  
  267. Rtext:
  268.  
  269. ; Intuitext structure
  270.  
  271.         DC.B    $02,$01,$01         ; FrontPen,BackPen,DrawMode
  272.  
  273.         Even                        ; Fill to make even address for word
  274.  
  275.         DC.W    $06,$03             ; Left edge, top edge
  276.         DC.L    $00                 ; No special font
  277.         DC.L    Rtx                 ; The actual text
  278.         DC.L    $00                 ; No next text 
  279.  
  280. _intuitionbase: DS.L    $01         ; memory for intuition base
  281. Returnmsg:      DS.L    $01         ; memory for WB return message
  282. Winhd:          DS.L    $01         ; memory for window handle
  283. Atx:            DC.B    "Reboot?",$00
  284. Ltx:            DC.B    "No",$00
  285. Rtx:            DC.B    "Yes",$00
  286. WinName:        DC.B    "   Your Choice",$00
  287. Screentitle:    DC.B    "FREEWARE - A N Peck (1995)",$00
  288. Intname:        DC.B    "intuition.library",$00  ; intuition library name
  289.  
  290.                 End     ; Adios Amigas
  291.  
  292.  
  293.